﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace PlutoStudio.Net.Processors.Configuration
{
    public class ProcessorSection : ConfigurationSection
    {
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public ProcessorCollection Processors
        {
            get
            {
                return (ProcessorCollection)base[""];
            }
        }
    }

    public class ProcessorCollection : ConfigurationElementCollection
    {

        protected override ConfigurationElement CreateNewElement()
        {
            return new ProcessorConfigSection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ProcessorConfigSection)element).Name;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "processor";
            }
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            base.BaseAdd(element, false);
        }

        public ProcessorConfigSection this[int index]
        {
            get
            {
                return (ProcessorConfigSection)BaseGet(index);
            }
        }

        public new ProcessorConfigSection this[string name]
        {
            get
            {
                return (ProcessorConfigSection)BaseGet(name);
            }
        }

    }

    public class ProcessorConfigSection : ConfigurationSection
    {
        [ConfigurationProperty("name")]
        public string Name { get { return (string)base["name"]; } }

        [ConfigurationProperty("flag", IsKey = true)]
        public ushort Flag { get { return (ushort)base["flag"]; } }

        [ConfigurationProperty("type")]
        public string Type { get { return (string)base["type"]; } }

        [ConfigurationProperty("", IsDefaultCollection = true)]
        public ActionCollection Actions
        {
            get
            {
                return (ActionCollection)base[""];
            }
        }
    }

    public class ActionCollection : ConfigurationElementCollection
    {

        protected override ConfigurationElement CreateNewElement()
        {
            return new ActionConfigSection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ActionConfigSection)element).Name;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName
        {
            get
            {
                return "action";
            }
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            base.BaseAdd(element, false);
        }

        public ActionConfigSection this[int index]
        {
            get
            {
                return (ActionConfigSection)BaseGet(index);
            }
        }

        public new ActionConfigSection this[string name]
        {
            get
            {
                return (ActionConfigSection)BaseGet(name);
            }
        }

    }

    public class ActionConfigSection : ConfigurationSection
    {
        [ConfigurationProperty("name")]
        public string Name { get { return (string)base["name"]; } }

        [ConfigurationProperty("code", IsKey = true)]
        public ushort Code { get { return (ushort)base["code"]; } }

    }

}
